package pl.nazaweb.imedproplus.model.entity;

import pl.nazaweb.imedproplus.model.interfaces.IVisit;
import java.io.Serializable;
import java.util.Date;
import java.util.List;
import javax.persistence.*;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

@Entity
@Table(name = "visit")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Visit.findAll", query = "SELECT v FROM Visit v"),
    @NamedQuery(name = "Visit.findById", query = "SELECT v FROM Visit v WHERE v.id = :id"),
    @NamedQuery(name = "Visit.findByDateFrom", query = "SELECT v FROM Visit v WHERE v.dateFrom = :dateFrom"),
    @NamedQuery(name = "Visit.findByDateTo", query = "SELECT v FROM Visit v WHERE v.dateTo = :dateTo"),
    @NamedQuery(name = "Visit.findByStatus", query = "SELECT v FROM Visit v WHERE v.status = :status"),
    @NamedQuery(name = "Visit.findByNfzOrganizationUnitCode", query = "SELECT v FROM Visit v WHERE v.nfzOrganizationUnitCode = :nfzOrganizationUnitCode"),
    @NamedQuery(name = "Visit.findByAuthorizingDate", query = "SELECT v FROM Visit v WHERE v.authorizingDate = :authorizingDate")})
public class Visit implements Serializable, IVisit {

    @Column(name = "date_from")
    @Temporal(TemporalType.TIMESTAMP)
    private Date dateFrom;
    @Column(name = "date_to")
    @Temporal(TemporalType.TIMESTAMP)
    private Date dateTo;
    @Column(name = "authorizing_date")
    @Temporal(TemporalType.TIMESTAMP)
    private Date authorizingDate;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "visit")
    private List<Diagnosis> diagnosisList;
    private static final long serialVersionUID = 1L;
    @Id
    @Basic(optional = false)
    @NotNull
    @SequenceGenerator(name = "visit_sequence_", sequenceName = "visit_sequence", allocationSize=1)
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "visit_sequence_")
    @Column(name = "id")
    private Long id;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 10)
    @Column(name = "status")
    private String status;
    @Size(max = 15)
    @Column(name = "nfz_organization_unit_code")
    private String nfzOrganizationUnitCode;
    @ManyToMany(mappedBy = "visitList")
    private List<Icd10> icd10List;
    @JoinColumn(name = "authorizing_staff", referencedColumnName = "id")
    @ManyToOne
    private Staff authorizingStaff;
    @JoinColumn(name = "referral", referencedColumnName = "id")
    @ManyToOne
    private Referral referral;
    @JoinColumn(name = "patient", referencedColumnName = "id")
    @ManyToOne
    private Patient patient;
    @JoinColumn(name = "organization_unit", referencedColumnName = "id")
    @ManyToOne
    private OrganizationStructure organizationUnit;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "visit")
    private List<VisitProcedure> visitProcedureList;

    public Visit() {
    }

    public Visit(Long id) {
        this.id = id;
    }

    public Visit(Long id, String status) {
        this.id = id;
        this.status = status;
    }

    @Override
    public Long getId() {
        return id;
    }

    @Override
    public void setId(Long id) {
        this.id = id;
    }

    @Override
    public Date getDateFrom() {
        return dateFrom;
    }

    @Override
    public void setDateFrom(Date dateFrom) {
        this.dateFrom = dateFrom;
    }

    @Override
    public Date getDateTo() {
        return dateTo;
    }

    @Override
    public void setDateTo(Date dateTo) {
        this.dateTo = dateTo;
    }

    @Override
    public String getStatus() {
        return status;
    }

    @Override
    public void setStatus(String status) {
        this.status = status;
    }

    @Override
    public String getNfzOrganizationUnitCode() {
        return nfzOrganizationUnitCode;
    }

    @Override
    public void setNfzOrganizationUnitCode(String nfzOrganizationUnitCode) {
        this.nfzOrganizationUnitCode = nfzOrganizationUnitCode;
    }

    @Override
    public Date getAuthorizingDate() {
        return authorizingDate;
    }

    @Override
    public void setAuthorizingDate(Date authorizingDate) {
        this.authorizingDate = authorizingDate;
    }

    @XmlTransient
    @Override
    public List<Icd10> getIcd10List() {
        return icd10List;
    }

    @Override
    public void setIcd10List(List<Icd10> icd10List) {
        this.icd10List = icd10List;
    }

    @Override
    public Staff getAuthorizingStaff() {
        return authorizingStaff;
    }

    @Override
    public void setAuthorizingStaff(Staff authorizingStaff) {
        this.authorizingStaff = authorizingStaff;
    }

    @Override
    public Referral getReferral() {
        return referral;
    }

    @Override
    public void setReferral(Referral referral) {
        this.referral = referral;
    }

    @Override
    public Patient getPatient() {
        return patient;
    }

    @Override
    public void setPatient(Patient patient) {
        this.patient = patient;
    }

    @Override
    public OrganizationStructure getOrganizationUnit() {
        return organizationUnit;
    }

    @Override
    public void setOrganizationUnit(OrganizationStructure organizationUnit) {
        this.organizationUnit = organizationUnit;
    }

    @XmlTransient
    @Override
    public List<VisitProcedure> getVisitProcedureList() {
        return visitProcedureList;
    }

    @Override
    public void setVisitProcedureList(List<VisitProcedure> visitProcedureList) {
        this.visitProcedureList = visitProcedureList;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Visit)) {
            return false;
        }
        Visit other = (Visit) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "pl.nazaweb.imedproplus.model.entity.Visit[ id=" + id + " ]";
    }

    @XmlTransient
    @Override
    public List<Diagnosis> getDiagnosisList() {
        return diagnosisList;
    }

    @Override
    public void setDiagnosisList(List<Diagnosis> diagnosisList) {
        this.diagnosisList = diagnosisList;
    }
}
